package com.javatest.springbootvalidate.service;

import com.javatest.springbootvalidate.entities.Order;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.validation.ConstraintViolation;
import javax.validation.Validator;
import java.util.Set;

@Service
public class ValidationService {

    @Autowired
    private Validator validator;

    public boolean validateBean(Order order) {
        Set<ConstraintViolation<Order>> validate = validator.validate(order);
        if (validate.size() > 0) {
            return false;
        }
        return true;
    }
}
